#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>

#include "CmdFile.h"

void cmdHelp( const char* argv0 )
{
	cout << "\n\t";
	cout << argv0 << " [INPUT] [NUM_OUTPUT_FILES]" << endl;
}

/*!
*/
int main( int argc, char** argv )
{
	string infn = "run_experiment.vlc";
	string outfn = "run_experiment.rand.vlc";


	if( argc > 1 ) {
		infn = argv[1];

		if( argc > 2 ) {
			outfn = argv[2];
		}
		else
		{
			outfn = infn.substr(0,infn.length()-3);
			outfn += "rand.";
			outfn += infn.substr(infn.length()-3);
		}
	}

	// read in file
	CmdFile cmdFile;
	{
		ifstream infile( infn.c_str() );
		if( !infile.is_open() ) {
			cout << "Unable to open file " << infn << " for reading!" << endl;
			cmdHelp(argv[0]);
			return -1;
		}

		string line;
		while( !infile.eof() )
		{
			getline (infile,line);
			cmdFile.addLine( line );
		}
		infile.close();
	}

	// randomize groups
	cmdFile.randomize();

	// write out file
	ofstream out( outfn.c_str() );
	if( !out.is_open() ) {
		cout << "Unable to open file " << outfn << " for writing!" << endl;
		cmdHelp(argv[0]);
		return -1;
	}
	cmdFile.write( out );
	out.close();

	return 1;
}